home *** CD-ROM | disk | FTP | other *** search
/ Total Web Page (Professional Suite) / Total Web Page 99.iso / CGI / DOWNLOAD.CGI-S=DANO&C=TXT&F=DAN_O.PL < prev    next >
Perl Script  |  1996-06-03  |  3KB  |  117 lines

  1. #!/usr/local/bin/perl
  2. #
  3. # "Book 'em, Dan-O" Logger Script by Spider
  4. # Created 9 July 1996
  5. # Email me at  spider@servtech.com
  6. # http://www.servtech.com/public/spider
  7. #
  8. # Secret Decoder Ring - aka Organization of Log File
  9. # Time Stamp / Person\Machine / Referring URL / Browser Used
  10. # This script can be run as a SSI or used 
  11. # in a "redirect" fashion via *normal* CGI calls.
  12.  
  13. ########## Set Variables ############
  14.  
  15. $SSI = 0;  
  16. # 0 if not used as a SSI  -    1 if used as a SSI
  17.  
  18. $logfile = "/absolute/path/to/dan_o.dat";  
  19. # change the directory path, silly!
  20.  
  21. $exclude = 0; 
  22. # 1 if you want to exclude YOUR IP/Domain/Machine Name  - 0 otherwise
  23.  
  24. $my_addr = "your.machine.name";  
  25. # used with the "exclude" portion
  26.  
  27. $HomeDirURL = "http://yourdomain.com/your/path/";  
  28. # change this if you're not using SSI's
  29.  
  30. $nextfile = "file.html";  
  31. # again, change if you're not using SSI's 
  32.  
  33. ########## So much for that.. On with the show! #######
  34.  
  35. # Get the input
  36. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  37.  
  38. # Split the name-value pairs
  39. @pairs = split(/&/, $buffer);
  40.  
  41. foreach $pair (@pairs) {
  42.     ($name, $value) = split(/=/, $pair);
  43.  
  44.     # Un-Webify plus signs and %-encoding
  45.     $value =~ tr/+/ /;
  46.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  47.  
  48.     # Stop people from using subshells to execute commands
  49.     # Not a big deal when using sendmail, but very important
  50.     # when using UCB mail (aka mailx).
  51.     $value =~ s/~!/ ~!/g; 
  52.  
  53.     # Uncomment for debugging purpose
  54.     # print "Setting $name to $value<P>";
  55.     $FORM{$name} = $value;
  56. }
  57.  
  58. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  59.  
  60. if ($sec < 10) {
  61.     $sec = "0$sec";
  62. }
  63. if ($min < 10) {
  64.     $min = "0$min";
  65. }
  66. if ($hour < 10) {
  67.     $hour = "0$hour";
  68. }
  69. if ($mon < 10) {
  70.     $mon = "0$mon";
  71. }
  72. if ($mday < 10) {
  73.     $mday = "0$mday";
  74. }
  75.  
  76. $month = ($mon + 1);
  77. @months = ("January","February","March","April","May","June","July","August","September","October","November","December");
  78. $date = "$hour\:$min\:$sec $month/$mday/$year";
  79.  
  80. # Now that we know what the time/date is.. let's have fun
  81.  
  82. if ($SSI == 1) {
  83.     if ($exclude == 1) {
  84.         &log unless ($ENV{'REMOTE_HOST'} eq $my_addr);
  85.     } else {
  86.     &log;
  87.     }
  88.     exit;
  89. }
  90.  
  91. if ($SSI == 0) {
  92.     if ($exclude == 1) {
  93.         &log unless ($ENV{'REMOTE_HOST'} eq $my_addr);
  94.     } else {
  95.     &log;
  96.     }
  97.     &redir;
  98.     exit;
  99. }
  100.  
  101. sub log {
  102.  
  103.     if (! open(LOG,">>$logfile")) {
  104.         print "Content-type: text/html\n\n";
  105.         print "Couldn't open $logfile so I'm bugging out..\n";
  106.         exit;
  107.     }
  108.     print LOG "At $date, $ENV{'REMOTE_HOST'} came here from $ENV{'HTTP_REFERER'} using $ENV{'HTTP_USER_AGENT'}.\n";
  109.     close (LOG);
  110. }
  111.  
  112. sub redir {
  113.     print "Location: $HomeDirURL$nextfile\n\n";
  114. }
  115.  
  116.